<template>
  <div>
    <el-button
      style="margin-bottom: 10px"
      @click="
        () => {
          $router.go(-1);
        }
      "
      >返回</el-button
    >
    <el-card>
      <el-form :inline="true" :model="query" label-width="100px" size="small">
        <!-- 公司级别 -->
        <!-- <el-form-item class="query-form-item">
          <span>公司级别：</span>
          <el-select
            v-model="query.performanceLevel"
            placeholder="请选择公司级别"
            @change="onSubmit"
            clearable
          >
            <el-option
              label="全球公司"
              value="1"
            ></el-option>
            <el-option
              label="省级公司"
              value="2"
            ></el-option>
            <el-option
              label="市级公司"
              value="3"
            ></el-option>
            <el-option
              label="县级公司"
              value="4"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <!-- 公司类型 -->
        <el-form-item class="query-form-item">
          <span>公司类型：</span>
          <el-select
            v-model="query.companyType"
            placeholder="请选择公司类型"
            @change="onSubmit"
            clearable
          >
            <!-- <el-option label="全部" value></el-option> -->
            <el-option label="孵化" value="0"></el-option>
            <el-option label="临时" value="1"></el-option>
            <el-option label="正式" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :model="query" size="small">
        <!-- 关键词检索 -->
        <el-form-item>
          <span> 公司名称：</span>
          <el-form-item class="query-form-item">
            <el-input
              v-model="query.companyName"
              placeholder="请输入公司名称"
              prefix-icon="el-icon-search"
              clearable
              style="magrin-left: 30px"
            ></el-input>
          </el-form-item>
        </el-form-item>
        <!-- 查询框 -->
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onRest"
          ></el-button>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <!-- table表单 -->
      <el-table
        ref="singleTable"
        :data="tableData"
        v-loading="loading"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
          width="50"
          fixed
        >
        </el-table-column>
        <el-table-column
          prop="companyType"
          align="center"
          label="公司类型"
          width="120"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.companyType == 0" style="color: #4acf1e"
              >孵化</span
            >
            <span v-else-if="scope.row.companyType == 1" style="color: #4acf1e"
              >临时</span
            >
            <span v-else-if="scope.row.companyType == 2" style="color: #4acf1e"
              >正式</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="performanceLevel"
          align="center"
          label="品牌公司级别"
          width="200"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.performanceLevel == 1" style="color: #4acf1e"
              >全球公司</span
            >
            <span
              v-else-if="scope.row.performanceLevel == 2"
              style="color: #4acf1e"
              >省级公司</span
            >
            <span
              v-else-if="scope.row.performanceLevel == 3"
              style="color: #4acf1e"
              >市级公司</span
            >
            <span
              v-else-if="scope.row.performanceLevel == 4"
              style="color: #4acf1e"
              >县级公司</span
            >
          </template>
        </el-table-column>

        <el-table-column
          prop="companyId"
          align="center"
          :show-overflow-tooltip="true"
          label="品牌公司ID"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="companyName"
          align="center"
          :show-overflow-tooltip="true"
          label="品牌公司名称"
          width="200"
        ></el-table-column>
        <el-table-column
          prop="companyRelationId"
          align="center"
          label="开发关系ID"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="performanceRelationLevel"
          align="center"
          label="开发关系公司级别"
          width="200"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.performanceRelationLevel == 1"
              style="color: #4acf1e"
              >全球公司</span
            >
            <span
              v-else-if="scope.row.performanceRelationLevel == 2"
              style="color: #4acf1e"
              >省级公司</span
            >
            <span
              v-else-if="scope.row.performanceRelationLevel == 3"
              style="color: #4acf1e"
              >市级公司</span
            >
            <span
              v-else-if="scope.row.performanceRelationLevel == 4"
              style="color: #4acf1e"
              >县级公司</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="companyRelationName"
          align="center"
          :show-overflow-tooltip="true"
          label="开发关系公司名称"
          width="200"
        ></el-table-column>

        <el-table-column align="center" label="操作" width="300" fixed="right">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="setRelation(scope.row)"
              >设为新增公司开发关系</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination-container"
        background
        :page-size="query.page.pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :current-page="query.page.currentPage"
        :page-sizes="[5, 10, 20, 30, 50]"
        :total="totalNumber"
      ></el-pagination>
    </el-card>
  </div>
</template>
<script>
import { getDevelopRelationList } from "../../api/handWork/handWorkList";
export default {
  data() {
    return {
      tableData: [],
      query: {
        newCompanyLevel: "", //上页面传递公司级别
        companyType: "", //公司类型
        companyName: "", //公司名称
        performanceLevel: "", //公司级别
        page: {
          currentPage: 1,
          pageSize: 5,
        },
      },
      totalNumber: 0,
      loading: false,
    };
  },
  created() {
    console.log("level", this.$route.params);
    this.query.newCompanyLevel = this.$route.params.level;
    this.getList();
  },
  methods: {
    //搜索
    onSubmit() {
      this.query.currentPage = 1;
      this.getList();
    },
    //刷新
    onRest() {
      this.query = {
        page: {
          currentPage: 1,
          pageSize: 5,
        },
        newCompanyLevel: "", //公司级别
        companyType: "", //公司类型
        companyName: "", //公司名称
        performanceLevel: "", //公司级别
        newCompanyLevel: this.$route.params.level,
      };
      this.getList();
    },
    handleSizeChange(val) {
      this.query.page.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.query.page.currentPage = val;
      this.getList();
    },
    getList() {
      this.loading = true;
      getDevelopRelationList(this.query)
        .then((res) => {
          console.log(res, "开发关系列表");
          if (res.code != 0) {
            this.$message.error(res.message);
            this.loading = false;
            return false;
          }
          this.loading = false;
          this.totalNumber = res.data.totalNumber;
          this.tableData = res.data.list;
        })
        .catch(() => {
          this.loading = false;
          this.tableData = [];
        });
    },
    //点击设置添加到新增品牌公司页面
    setRelation(row) {
      console.log(row);
      this.$router.push({
        name: "新增品牌公司",
        params: { type: "1", val: row },
      });
    },
  },
};
</script>

